<template>
	<view class="walletDetail safe-area">
		<view class="sticky">
			<view class="top">
				<view class="cate" @click="openPicker">
					<text>{{ columns[0][selectV - 1] }}</text>
					<uv-icon name="arrow-down"></uv-icon>
					<uv-picker ref="picker" :columns="columns" @confirm="confirm"></uv-picker>
				</view>
				<view class="income">
					<text>收入</text>
					<text>{{ income }}</text>
				</view>
				<view class="outcome">
					<text>支出</text>
					<text>{{ expenses }}</text>
				</view>
			</view>
			<view class="tabs">
				<uv-tabs :activeStyle="{ fontWeight: 'bold', color: '#121212' }" :list="tablist" :scrollable="false"
					@click="click" :defaultIndex="0"></uv-tabs>
			</view>
		</view>
		<view class="content">
			<view class="tabContent" v-if="selectV == 3 || selectV == 2 || selectV == 1">
				<view class="all">
					<view class="item" v-for="(item, index) in list" :key="index">
						<view class="tit">
							<text>{{ item.memo }}</text>
							<text>{{ item.money }}</text>
						</view>
						<view class="detail">
							<view class="sn">
								<text>订单编号:{{ item.service_ids }}</text>
								<!-- <text>线上消费</text> -->
							</view>
						</view>
						<view class="time">
							<text>{{ item.create_time_text }}</text>
						</view>
					</view>
				</view>
				<view v-if="list.length == 0" class="noData"> 暂无记录 </view>
				<!-- <view class="income" v-show="currentTab === 1">
					<text>收入</text>
				</view>
				<view class="outcome" v-show="currentTab === 2">
					<text>支出</text>
				</view> -->
			</view>
			<view class="tabContent" v-if="selectV == 4">
				<view class="fy" v-for="(item, index) in list" :key="item.id">
					<view class="user" v-if="item.source_id > 0">
						<image :src="$getImageURL(item.source.avatar)"></image>
						<view class="right">
							<view class="name">
								<text>{{ item.source.nickname }}</text>
								<text v-if="item.identity_name !== null"> {{ item.identity_name}} </text>
							</view>
							<view class="tel">
								<text>{{ item.source.mobile }}</text>
							</view>
						</view>
					</view>
					<view class="item">
						<view class="tit">
							<text>{{ item.memo }}</text>
							<text>{{ item.money }}</text>
						</view>
						<view class="detail">
							<view class="sn">
								<text>订单编号:{{ item.service_ids }}</text>
								<!-- <text>线上消费</text> -->
							</view>
						</view>
						<view class="time">
							<text>{{ item.create_time_text }}</text>
						</view>
					</view>
					<view class="fyDetail" v-if="item.source_id > 0">
						<block v-for="(subItem, idx) in item.profit_arr" :key="idx">
							<view class="abcd flex align-center just-between">
								<text>{{ subItem.name }}</text>
								<text class="txt">{{ subItem.money }}</text>
							</view>
						</block>
					</view>
				</view>
				<view v-if="list.length == 0" class="noData"> 暂无记录 </view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		walletDetail
	} from "@/API/wallet";
	import config from "@/common/config/config.js";
	export default {
		data() {
			return {
				cdnurl: config.cdnurl,
				tablist: [{
						name: "全部",
					},
					{
						name: "收入",
					},
					{
						name: "支出",
					},
				],
				columns: [
					["销售钱包", "红包钱包", "余额钱包", "分佣钱包"]
				],
				list: [], //数据
				income: 0, //收入
				expenses: 0, //支出
				currentTab: 0,
				selectV: 1,
				current_page: 1,
				last_page: 1,
			};
		},
		methods: {
			async getDetail() {
				const res = await walletDetail({
					wallet_type: this.selectV,
					type: this.currentTab,
					page: this.current_page,
				});
				const {
					income,
					expenses,
					list
				} = res.data;
				this.income = income;
				this.expenses = expenses;
				this.list = this.list.concat(list.data);
				this.current_page = list.current_page;
				this.last_page = list.last_page;
			},

			click(item) {
				this.currentTab = item.index;
				this.current_page = 1;
				this.list = [];
				this.getDetail();
			},
			openPicker() {
				this.$refs.picker.open();
			},
			confirm(e) {
				console.log("confirm", e);
				this.selectV = e.indexs[0] + 1;
				this.current_page = 1;
				this.list = [];
				this.getDetail();
			},
		},
		onLoad(options) {
			this.selectV = options.type;
			console.log(this.selectV);
		},
		onShow() {
			this.getDetail();
		},
		// 触底加载
		onReachBottom() {
			if (this.current_page >= this.last_page) {
				// uni.showToast({
				// 	title: "没有更多数据了",
				// 	icon: "none",
				// });
				// return false;
			} else {
				this.current_page++;
				this.getDetail();
			}
		},
	};
</script>

<style lang="scss" scoped>
	.walletDetail {
		background-color: #f6f6f6;
		min-height: 100vh;

		.noData {
			text-align: center;
			font-size: 28rpx;
			color: #999999;
			margin-top: 100rpx;
		}

		.tabs {
			background-color: #f6f6f6;
		}

		.sticky {
			position: sticky;
			top: 0;
			z-index: 99;
		}

		.top {
			display: flex;
			height: 100rpx;
			align-items: center;
			padding: 0 50rpx;
			background: linear-gradient(90deg, #dd551b, #f49355);

			.cate {
				display: flex;
				justify-content: center;
				align-items: center;
				width: 190rpx;
				height: 62rpx;
				background: #ffffff;
				border-radius: 10rpx;
				font-weight: 500;
				font-size: 28rpx;
				color: #121212;
			}

			.income {
				margin-left: auto;
				display: flex;
				justify-content: space-between;
				font-weight: 400;
				font-size: 26rpx;
				color: #ffffff;
			}

			.outcome {
				margin-left: 40rpx;
				display: flex;
				justify-content: space-between;
				font-weight: 400;
				font-size: 26rpx;
				color: #ffffff;
			}
		}

		.content {
			padding: 20rpx;

			.tabContent {
				margin-top: 20rpx;
				display: flex;
				flex-direction: column;
				gap: 20rpx;

				.fy {
					background-color: white;
					border-radius: 30rpx;
					padding: 20rpx;

					.item {
						border-radius: 0 !important;
						border-top: 1rpx solid #f4f4f4;
						padding: 20rpx 0 0;
						margin-top: 20rpx;
					}

					.fyDetail {
						display: flex;
						flex-direction: column;
						border-top: 1rpx solid #f4f4f4;
						padding: 20rpx 0 0;
						margin-top: 20rpx;
						
						.abcd {
							color: #888888;
							
							.txt {
								color: #dd551b;
							}
						}
					}

					.user {
						display: flex;
						align-items: center;
						font-weight: bold;
						font-size: 28rpx;
						color: #121212;

						image {
							width: 80rpx;
							height: 80rpx;
							margin-right: 20rpx;
						}

						.right {
							display: flex;
							flex-direction: column;

							.name {
								display: flex;
								align-items: center;

								text:nth-child(1) {
									font-weight: bold;
									font-size: 32rpx;
									color: #121212;
								}

								text:nth-child(2) {
									width: 90rpx;
									height: 36rpx;
									background: linear-gradient(90deg, #dd551b, #f49355);
									border-radius: 5rpx;
									font-weight: 400;
									font-size: 20rpx;
									color: #fdfdfd;
									margin-left: 10rpx;
									text-align: center;
									line-height: 36rpx;
								}
							}

							.tel {
								margin-top: 10rpx;
								font-weight: 400;
								font-size: 26rpx;
								color: #888888;
							}
						}
					}
				}

				.item {
					padding: 20rpx;
					background: #ffffff;
					border-radius: 16rpx;
					margin-bottom: 20rpx;

					.tit {
						display: flex;
						justify-content: space-between;
						font-weight: 400;
						font-size: 26rpx;
						color: #121212;

						text:nth-child(2) {
							color: #dd551b;
						}
					}

					.detail {
						margin-top: 20rpx;

						.sn {
							display: flex;
							justify-content: space-between;
							font-weight: 400;
							font-size: 26rpx;
							color: #888888;
						}
					}

					.time {
						margin-top: 20rpx;
						font-weight: 400;
						font-size: 26rpx;
						color: #888888;
					}
				}
			}
		}
	}

	/deep/.uv-tabs__wrapper__nav__line {
		background: linear-gradient(90deg, #dd551b, #f49355) !important;
	}
</style>